import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 30

        ColumnLayout{
            spacing: 10
            Layout.alignment: Qt.AlignTop

            SAxisModulePos{
                moduleName: "LTLoaderBeltZ"
                posName: "DownPos"
            }
            SAxisModulePos{
                moduleName: "LTLoaderBeltZ"
                posName: "StandbyPos"
            }
            SAxisModulePos{
                moduleName: "LTLoaderBeltZ"
                posName: "UpPos"
            }
            SAxisModulePos{
                moduleName: "LTLoaderTrackX"
                posName: "LoadTrayPos"
            }
            SAxisModulePos{
                moduleName: "LTLoaderTrackX"
                posName: "SafetyPosForLTBufferZ"
            }
            SAxisModulePos{
                moduleName: "LTLoaderTrackX"
                posName: "LeftLensPrPos"
            }
            SAxisModulePos{
                moduleName: "LTLoaderTrackX"
                posName: "UnloadTrayPos"
            }
        }

        ColumnLayout{
            spacing: 10
            Layout.alignment: Qt.AlignTop

            ConfigRow{
                configName: "ltLoaderBeltRunDir"
                configModel: ltModuleConfig
                Component.onCompleted: {
                    init(ConfigElementType.Other)
                }
            }
            ConfigRow{
                configName: "ltLoaderPushOutTrayTimeout"
                configModel: ltModuleConfig
                Component.onCompleted: {
                    init(ConfigElementType.Int)
                }
            }

            RowLayout{
                Button{
                    text: qsTr("LoadTray")
                    onClicked: {
                        lensTrayLoader.handleDebugEvent("manuallyLoadTray")
                    }
                }
                Button{
                    text: qsTr("UnloadTray")
                    onClicked: {
                        lensTrayLoader.handleDebugEvent("manuallyUnloadTray")
                    }
                }
            }

            GroupBox{
                title: qsTr("LoadUnloadTrayLoopTest")
                ColumnLayout{
                    RowLayout{
                        Label{
                            text: qsTr("Times:")
                        }
                        TextField{
                            id: loopTestTimes
                            implicitWidth: 80
                            validator: IntValidator{}
                            text: "100"
                            selectByMouse: true
                        }
                    }
                    RowLayout{
                        Button{
                            text: qsTr("Start")
                            onClicked: {
                                lensTrayLoader.handleDebugEvent("startLoadUnloadTrayLoopTest", [loopTestTimes.text])
                            }
                        }
                        Button{
                            text: qsTr("Stop")
                            onClicked: {
                                lensTrayLoader.stopLoadUnloadTrayLoopTest()
                            }
                            ToolTip{
                                text: qsTr("You have to click 'Reset' button after loop test stopped.")
                                visible: parent.hovered
                            }
                        }
                        Button{
                            text: qsTr("Reset")
                            onClicked: {
                                lensTrayLoader.resetLoadUnloadTrayLoopTest()
                            }
                        }
                    }
                }
            }
        }
    }
}
